<style>
    .mytitle{
        display: none;
    }
</style>
<!--表单内容-->
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'naddress-form',
	'enableAjaxValidation'=>false,
        'enableClientValidation'=>true,
        'clientOptions'=>array(
            'validateOnSubmit'=>true
        ),
    'htmlOptions'=>array('class'=>'ajax_form'),
)); ?>
<table>
	<tr>
                <td style="display: none;">
                    <input name="phone" value="<?php echo $phone; ?>"/>
                    <input name="code" value="<?php echo $code; ?>"/>
                </td>
<!--		<td align="right"><?php echo $form->labelEx($model,'phone'); ?></td>
		<td>
			<?php echo $form->textField($model,'phone',array('size'=>20,'maxlength'=>20,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'phone'); ?>
		</td>
		<td align="right"><?php echo $form->labelEx($model,'code'); ?></td>
		<td>
			<?php echo $form->textField($model,'code',array('size'=>20,'maxlength'=>20,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'code'); ?>
		</td>-->
		<td align="right"><?php echo $form->labelEx($model,'province'); ?></td>
		<td>
			<?php echo $form->textField($model,'province',array('size'=>10,'maxlength'=>10,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'province'); ?>
		</td>   
		<td align="right"><?php echo $form->labelEx($model,'city'); ?></td>
		<td>
			<?php echo $form->textField($model,'city',array('size'=>10,'maxlength'=>10,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'city'); ?>
		</td>                     
	</tr>

	<tr>         
		<td align="right"><?php echo $form->labelEx($model,'area'); ?></td>
		<td>
			<?php echo $form->textField($model,'area',array('size'=>10,'maxlength'=>10,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'area'); ?>
		</td>
<!--		<td align="right"><?php echo $form->labelEx($model,'is_used'); ?></td>
		<td>
			<?php echo $form->textField($model,'is_used',array('class'=>'fl input')); ?>
			<?php echo $form->error($model,'is_used'); ?>
		</td>-->
		<td align="right"><?php echo $form->labelEx($model,'address'); ?></td>
                <td colspan="4">
			<?php echo $form->textField($model,'address',array('size'=>60,'maxlength'=>255,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'address'); ?>
		</td>                  
	</tr>
</table>
<div style="float: right;">
    <input class="but" type="submit" name="yt0" value="新增地址" />        </td>   
</div>
<?php $this->endWidget(); ?>
<!--表单内容-->
<div>
    <table cellspacing="1" class="mylist2" style="margin-top: 20px;">
          
                    <tr class="mylist_title">
                            <td>序号</td>
                            <td>省份</td>
                            <td>城市</td>
                            <td>地区</td>
                            <td>详细地址</td>
                             <td>创建人</td>
                            <td>创建时间</td>
                           
                            <td>操作</td>
                    </tr>
            
            <tbody>
                    <?php 
                    $res_count = count($result);
                    for($i=0;$i<$res_count;$i++){?>
                    <tr class="datalist" style="text-align: center;">			
                            <td><?php echo ($i+1);?></td>
                            <td><?php echo $result[$i]['province'];?></td>
                            <td><?php echo $result[$i]['city'];?></td>
                            <td><?php echo $result[$i]['area'];?></td>
                            <td><?php echo $result[$i]['address'];?></td>
                            <td><?php echo $result[$i]['username'];?></td>
                            <td><?php echo $result[$i]['add_time'];?></td>
                            <td>
                                <?php 
                                  if($result[$i]['is_use']==1){
                                      echo '默认地址';
                                  }  else {
                                      echo CHtml::link('设为默认', 'javascript:setDefault('.$result[$i]['id'].',1);');
                                  }  
                                ?>
                                &nbsp;&nbsp;
                            </td>
                    </tr>
                    <?php 
                    }
                    foreach ($data as $value) {
                        $res_count+=1;
                     ?>
                    <tr class="datalist" style="text-align: center;">
                            <td><?php echo $res_count;?></td>
                            <td><?php echo $value->province;?></td>
                            <td><?php echo $value->city;?></td>
                            <td><?php echo $value->area;?></td>
                            <td><?php echo $value->address;?></td>
                            <td><?php echo $value->create_user;?></td>
                            <td><?php echo $value->create_time;?></td>
                            <td>
                                <?php 
                                  if($value->is_used==1){
                                      echo '默认地址';
                                  }  else {
                                      echo CHtml::link('设为默认', 'javascript:setDefault('.$value->id.',2);');
                                  }  
                                ?>                                
                                <?php echo CHtml::link('删除', 'javascript:deleteSelect('.$value->id.');'); ?>
                            </td>                        
                    </tr>
                    <?php
                    }
                    ?>
            </tbody>
    </table>    
</div>
<script type="text/javascript">
    function deleteSelect(id){
        ajaxSubmitdeleteSelect(id,'<?php echo Yii::app()->createUrl('naddress/delete',array('id'=>0)) ?>');
    }
    function setDefault(id,type){
        ajaxSubmitDefault(id,type,'<?php echo Yii::app()->createUrl('naddress/default',array('id'=>0)) ?>');
    } 
    function ajaxSubmitDefault(id,type,url){
        if(id==0){
            var ids=new Array();
            $('input[name="id[]"]').each(function(){
                if($(this).attr("checked"))
                    ids.push($(this).val());
            });
            id=ids;
        }
        art.dialog({
                lock: true,
                background: '#600',
                opacity: 0.6,
                content: '确认修改？',
                icon: 'warning',
                ok:function(){
                    $.ajax({
                        type:"POST",
                        dataType:"json",
                        data:{"id":id,'type':type},
                        url:url,
                        success:function(json) {
                            if(json.result==0){
                                parent.document.getElementById("Party_province").innerHTML=json.province;            
                                parent.document.getElementById("Party_city").innerHTML=json.city; 
                                parent.document.getElementById("Party_area").innerHTML=json.area; 
                                parent.document.getElementById("Party_address").innerHTML=json.address; 
                                location.reload();
                            }else{
                                art.dialog({icon:'error',content:'操作数据失败。。。',time:1});
                            }
                        }
                    });
                },
                cancel: function(){}
     });
}    
</script>
